function requestLocalNotificationPermission() {
    cordova.plugins.notification.local.requestPermission(function() {
        document.getElementById("notificationPermission").innerHTML = "授权成功";
    });
}

function hasLocalNotificationPermission() {
    cordova.plugins.notification.local.hasPermission(function() {
        document.getElementById("hasNotificationPermission").innerHTML = "有授权";
    });
}
function createChannel() {
    cordova.plugins.notification.local.createChannel({
        androidChannelId: "my_channel_01", // string, to separate something in the id, use "_" instead of "-"
        androidChannelName: "My Channel Name", // string, defaults to "Default Channel"
        androidChannelDescription: "Description of channel", // string (optional)
        androidChannelImportance: "IMPORTANCE_DEFAULT", // string (optional)
        androidChannelEnableLights: true, // boolean (optional), default is false
        androidChannelEnableVibration: true, // boolean (optional), default is false
        sound: 'www/audio/ring.mp3', // string (optional)
        androidChannelSoundUsage: 5 // int (optional), default is USAGE_NOTIFICATION
    }, function(){
        document.getElementById("channelInfo").innerHTML = "创建成功";
    }, this);
}

function deleteChannel() {
    cordova.plugins.notification.local.deleteChannel("my_channel_01", function() {
        document.getElementById("deleteInfo").innerHTML = "删除成功";
    }, this);
}

function addActions() {
    cordova.plugins.notification.local.addActions('REPLY_NO_CATEGORY', [
        {
            title: 'Reply',
            wantAgentInfo:{
                wants: [
                    {
                        bundleName: 'com.ionicframework.chuzhitong410158',
                        abilityName: 'EntryAbility',
                    }
                ],
                actionType: 1,
                requestCode: 0,
                actionFlags:[4]
            }
        }
    ]);
}
function sendLocalNotificationAtOnce() {
    cordova.plugins.notification.local.on("add", (notification, eopts) => {
        document.getElementById("atOnceInfo").innerHTML = "发送成功";
    });

    cordova.plugins.notification.local.schedule({
        id: 6,
        title: 'Design team meeting',
        text: '3:00 - 4:00 PM\n请注意开会时间。',
        wantAgentInfo:{
            wants: [
                {
                    bundleName: 'com.ionicframework.chuzhitong410158',
                    abilityName: 'EntryAbility',
                }
            ],
            actionType: 1,
            requestCode: 0,
            actionFlags:[4]
        },
        androidMessages: [
            { person: 'Me', message: 'I miss you' },
            { person: 'Irish', message: 'I miss you more!' },
            { person: 'Me', message: 'I always miss you more by 10%' }
        ],
        actions: 'REPLY_NO_CATEGORY'
    },function(notification){
        console.log(notification);
        document.getElementById("atOnceInfo").innerHTML = "发送成功";
    });
}

function sendLocalNotificationProgress() {
    cordova.plugins.notification.local.on("add", (notification, eopts) => {
        document.getElementById("barInfo").innerHTML = "发送成功";
    });
    cordova.plugins.notification.local.schedule({
        id: 6,
        title: 'Design team meeting',
        text: '3:00 - 4:00 PM',
        androidProgressBar: {
            name:"下载标题",
            data:{
                title:"下载中",
                fileName:"文件名",
                progressValue:45
            }
        }
    },function(notification){
        console.log(notification);
        document.getElementById("barInfo").innerHTML = "发送成功";
    });
}

function sendLocalNotificationUpdateProgress() {
    cordova.plugins.notification.local.on("update", (notification, eopts) => {
        document.getElementById("barUpdateInfo").innerHTML = "更新成功";
    });
    cordova.plugins.notification.local.update({
        id: 6,
        title: 'Design team meeting',
        text: '3:00 - 4:00 PM',
        autoDeletedTime: new Date().getTime()+2000,
        androidProgressBar: {
            name:"下载标题",
            data:{
                title:"下载中",
                fileName:"文件名",
                progressValue:100
            }
        }
    },function(notification){
        console.log(notification);
        document.getElementById("barUpdateInfo").innerHTML = "更新成功";
    });
}
function deleteLocalNotification() {
    cordova.plugins.notification.local.cancel([6]
        ,function(notification){
            document.getElementById("deleteSingleInfo").innerHTML = "清除成功";
        });
}
function deleteAllLocalNotification() {
    cordova.plugins.notification.local.cancelAll(function(notification){
        document.getElementById("deleteAllInfo").innerHTML = "清除成功";
    });
}
function getNotificationType() {
    cordova.plugins.notification.local.getType(6
        ,function(info){
            document.getElementById("typeInfo").innerHTML = info;
        });
}

function getNotificationIds() {
    cordova.plugins.notification.local.getIds(function(ids){
        document.getElementById("idsInfo").innerHTML = ids;
    });
}

function getNotificationJson() {
    cordova.plugins.notification.local.get([6,7]
        ,function(info){
            document.getElementById("jsonInfo").innerHTML = info;
        });
}

function openNotificationWindow() {
    cordova.plugins.notification.local.openNotificationSettings(function(){
        document.getElementById("windowInfo").innerHTML = "打开成功";
    });
}

function sendLocalNotificationAtAfter() {
    cordova.plugins.notification.local.schedule({
        id: 6,
        title: 'Design team meeting',
        text: '3:00 - 4:00 PM',
        trigger: { at: new Date().getTime()+100000 }
    },function(info) {
        document.getElementById("atInfo").innerHTML = info;
    });
}

function sendLocalNotificationAfterHour() {
    cordova.plugins.notification.local.schedule({
        id: 6,
        title: 'Design team meeting',
        text: '3:00 - 4:00 PM',
        trigger: { in: 1, unit: 'hour' }
    },function(info) {
        document.getElementById("inInfo").innerHTML = info;
    });
}

function sendLocalNotificationRepeat() {
    cordova.plugins.notification.local.schedule({
        id: 7,
        title: 'Design team meeting',
        text: '3:00 - 4:00 PM',
        trigger: { every: { month: 10, day: 27, hour: 9, minute: 0 } }
    },function(info) {
        document.getElementById("everyInfo").innerHTML = info;
    });
}

function sendLocalNotificationRepeatMonth() {
    cordova.plugins.notification.local.schedule({
        id: 9,
        title: 'Design team meeting',
        text: '3:00 - 4:00 PM',
        trigger: { every: 'month', count:1 }
    },function(info) {
        document.getElementById("everyMonthInfo").innerHTML = info;
    });
}
